package com.edu.internship.busi.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.edu.internship.busi.service.IAttachmentService;
import com.edu.internship.glabal.properties.SystemProperties;
import com.edu.internship.util.AttachUtils;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * [一句话描述该类的功能]
 *
 * @author : [Acer]
 * @version : [v1.0]
 * @createTime : [2022/8/9 15:40]
 */
@Service
@Slf4j
public class AttachmentServiceImpl implements IAttachmentService {

    @Resource
    private SystemProperties systemProperties;

    @SneakyThrows
    @Override
    public JSONObject uploadFileAttachment(MultipartFile file, String fileSpace) {
        String originalFileName = file.getOriginalFilename();
        if (Objects.isNull(originalFileName)) {
            return null;
        }

        JSONObject jsonObject = AttachUtils.uploadAttach(file, systemProperties.getFileDirectory(),
                fileSpace, systemProperties.getBaseUrl());

        //return super.saveAttachment(jsonObject, fileSpace);
        return jsonObject;
    }
}
